class Solution {
  public void merge(int[] A, int m, int[] B, int n) {
    int pa = m - 1;
    int pb = n - 1;
    int ps = m + n - 1;
    while (pa >= 0 && pb >= 0) {
      if (A[pa] > B[pb]) {
        A[ps] = A[pa];
        pa--;
      } else if (A[pa] < B[pb]) {
        A[ps] = B[pb];
        pb--;
      } else {
        A[ps--] = A[pa];
        A[ps] = B[pb];
        pa--;
        pb--;
      }
      ps--;
    }
    while (pb >= 0) {
      A[pb] = B[pb];
      pb--;
    }
  }
}